package com.yidu.boss.sys.service.impl;

import com.yidu.boss.sys.dao.BondMapper;
import com.yidu.boss.sys.domain.Bond;
import com.yidu.boss.sys.domain.BondExample;
import com.yidu.boss.sys.service.BondService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

/**
 * @version 1.0
 * @Author Zhi
 * @Date 2019/11/22 10:24
 **/

@Service
public class BondServiceImpl implements BondService {
    //定义债券接口
    @Autowired
    private BondMapper bondMapper;

    /**
     * 根据条件查询
     * @param bondExample
     * @return
     */
    @Override
    public List<Bond> selectByExample(BondExample bondExample) {
        return bondMapper.selectByExample(bondExample);
    }



    /**
     * 模糊查询所有
     * @param condition
     * @return
     */
    @Override
    public List<Bond> selectSomeByMore(String condition) {
        //调用业务层模糊查询所有的方法
        List<Bond> bondList = bondMapper.selectSomeByMore(condition);
        return bondList;
    }

    /**
     * 添加
     * @param bond
     * @return
     */
    @Override
    public int insertBond(Bond bond) {
        //Id
        bond.setBondid(UUID.randomUUID().toString().substring(0,6).replace("-",""));
        System.out.println("bond = " + bond);
        int i = bondMapper.insertSelective(bond);
        return i;
    }

    /**
     * 修改
     * @param bond
     * @return
     */
    @Override
    public int updateBond(Bond bond) {
        //Example类
        BondExample bondExample = new BondExample();
        //获得Id
        bondExample.or().andBondidEqualTo(bond.getBondid());
        int i = bondMapper.updateByExampleSelective(bond,bondExample);
        return i;
    }

    /**
     *删除
     * @param id
     * @return
     */
    @Override
    public int deleteBond(String id) {
        int i = bondMapper.deleteByPrimaryKey(id);
        System.err.println("i = " + i);
        return i;
    }
}
